﻿using AiXiu.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace AiXiu.WebSite
{
    /// <summary>
    /// CaptchaHandler 的摘要说明
    /// </summary>
    public class CaptchaHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //1、实例化CaptchaGenerator（图片验证码生成器）
            CaptchaGenerator captchaGenerator = new CaptchaGenerator();
            //2、拿到验证码
            string text = captchaGenerator.Text;
            //3、保存验证码到Session
            context.Session.Add("captcha", text);

            //4、拿到图片
            Bitmap img= captchaGenerator.Image;

            //5、输出验证码图片
            context.Response.ContentType = "image/jpeg";
            img.Save(context.Response.OutputStream, ImageFormat.Jpeg);
            context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}